package com.yun.zf.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.zf.admin.mapper.ZfHouseInfoRentMapper;
import com.yun.zf.admin.service.ZfHouseInfoRentService;
import com.yun.zf.common.app.domain.ZfHouseInfoRent;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 租房维护表 服务实现类
 * </p>
 *
 * @author cj
 * @since 2021-03-09
 */
@Service
public class ZfHouseInfoRentServiceImpl extends ServiceImpl<ZfHouseInfoRentMapper, ZfHouseInfoRent> implements ZfHouseInfoRentService {

    @Override
    public ZfHouseInfoRent addHouseInfoRent(ZfHouseInfoRent houseInfoRent) {
          baseMapper.insert(houseInfoRent);
        return houseInfoRent;
    }

    @Override
    public ZfHouseInfoRent motifyRent(ZfHouseInfoRent houseInfoRent) {
        QueryWrapper<ZfHouseInfoRent> rentQueryWrapper = new QueryWrapper<>();
        rentQueryWrapper.lambda().eq(ZfHouseInfoRent::getCityCode,houseInfoRent.getCityCode())
                .eq(ZfHouseInfoRent::getProvinceCode,houseInfoRent.getProvinceCode())
                .eq(ZfHouseInfoRent::getBasicId,houseInfoRent.getBasicId()).orderByAsc(ZfHouseInfoRent::getCreateTime);
       ZfHouseInfoRent rent = baseMapper.selectList( rentQueryWrapper).get(0);
        BeanUtil.copyProperties(houseInfoRent,rent);
         baseMapper.update(rent,rentQueryWrapper);
        return rent;
    }

    @Override
    public ZfHouseInfoRent getHouseInfoRent(Long basicId, Long provinceCode, Long cityCode) {
        QueryWrapper<ZfHouseInfoRent> rentQueryWrapper = new QueryWrapper<>();
        rentQueryWrapper.lambda().eq(ZfHouseInfoRent::getCityCode,cityCode)
                .eq(ZfHouseInfoRent::getProvinceCode,provinceCode)
                .eq(ZfHouseInfoRent::getBasicId,basicId);
        return baseMapper.selectOne(rentQueryWrapper);
    }
}
